#coding=utf-8
'''
3.2. Performing Accurate Decimal Calculations

use decimal module
from decimal import Decimal
'''
from decimal import Decimal, localcontext

a = Decimal('4.2')
b = Decimal('2.1')
print(a + b)
print(a + b == Decimal('6.3'))

a = Decimal('1.3')
b = Decimal('1.7')
print(a / b)

with localcontext() as ctx:
    ctx.prec = 3
    print(a / b)

with localcontext() as ctx:
    ctx.prec = 50
    print( a / b)